using System;
using Newtonsoft.Json;
using QFramework;
using UnityEngine;
using Resources = Bingo.Facades.Resources;

namespace Bingo.Config
{
	public static class ConfigHelper
	{
		public static string GetText(string key)
		{
			try
			{
				TextAsset textAsset = Resources.LoadSync<TextAsset>(BAssetBundle.Config.BundleName, key);
				return textAsset.text;
			}
			catch (Exception e)
			{
				throw new Exception($"load config file fail, key: {key}", e);
			}
		}
		
		public static string GetGlobal()
		{
			try
			{
//				GameObject config = (GameObject)ResourcesHelper.Load("KV");
//				string configStr = config.Get<TextAsset>("GlobalProto").text;
//				return configStr;

				return string.Empty;
			}
			catch (Exception e)
			{
				throw new Exception($"load global config file fail", e);
			}
		}

		public static T ToObject<T>(string str) 
		{
			return JsonConvert.DeserializeObject<T>(str);
		}
	}
}